package cn.tsinghua.comsmacitccntsinghua.service;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.Nullable;

import cn.tsinghua.comsmacitccntsinghua.DeviceInfo;

/**
 * @Author yjl
 * @create 2021/10/22 14:52
 */
public class KillSelfService extends Service {
    private Handler handler;
    private static final String TAG = "KillSelfService";

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d(TAG,"----onStartCommand");
        handler.postDelayed(() ->{
            Log.d(TAG,"----启动");
            Intent launchIntent = getPackageManager().getLaunchIntentForPackage(DeviceInfo.packageName);
            startActivity(launchIntent);
            KillSelfService.this.stopSelf();//停止此service
        },4000); //关闭app后4秒重启APP
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }
}
